package com.example.sharedpreferencedemo;

public final class SPUserInfo {
    // sp 对象
    private final static SPCache spCache = new SPCache(MainApplication.getContext(), "SPUserInfo");

    // 各种key常数定义
    private final static String userNameKey = "userNameKey";
    private final static String passwordKey = "passwordKey";

    // 读写接口
    public static void put(UserInfo userInfo) {
        spCache.put(userNameKey, userInfo.getUserName());
        spCache.put(passwordKey, userInfo.getPassword());
    }

    public static UserInfo get() {
        String userName = (String) spCache.get(userNameKey, "默认的名字");
        String password = (String) spCache.get(passwordKey, "默认的密码");
        return new UserInfo(userName, password);
    }
}


